package com.manor.main.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.manor.main.R;
import com.manor.main.bean.TxListBean;
import com.manor.main.custom.marqueeview.Utils;

public class TXWithdrawalAdapter extends BaseQuickAdapter<TxListBean.ListBean, BaseViewHolder> {
    String type = "0";

    public TXWithdrawalAdapter(int layoutResId, @Nullable List<TxListBean.ListBean> data, String type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, TxListBean.ListBean item) {
        helper.setText(R.id.tv_name, item.getOrderno());
        helper.setText(R.id.tv_money, "到账" + item.getMoney()+"元");
        TextView tv_context = helper.getView(R.id.tv_context);
        tv_context.setVisibility(View.VISIBLE);
      tv_context.setText("提现"+item.getVotes()+"余额");
        // helper.setText(R.id.tv_context, item.getId());
       Log.e("tag", item.getAddtime());
        try {
            helper.setText(R.id.tv_time, dateToStamp(item.getAddtime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        ImageView im_type = helper.getView(R.id.im_type);
        ViewGroup.LayoutParams lp;
        lp=im_type.getLayoutParams();
        if (type.equals("3")) {
            im_type.setImageResource(R.mipmap.pic_sdj);
            lp.width= Utils.sp2px(getContext(), 24);
            lp.height=Utils.sp2px(getContext(), 16);
        } else {
            if(type.equals("4")){
                if(item.getCash_type().equals("0")){
                    im_type.setImageResource(R.mipmap.pic_nengliang);
                    lp.width = Utils.sp2px(getContext(), 24);
                    lp.height = Utils.sp2px(getContext(), 24);
                } else {
                    im_type.setImageResource(R.mipmap.pic_sdj);
                    lp.width= Utils.sp2px(getContext(), 16);
                    lp.height=Utils.sp2px(getContext(), 16);
                }
            }else {
                im_type.setImageResource(R.mipmap.pic_nengliang);
                lp.width = Utils.sp2px(getContext(), 24);
                lp.height = Utils.sp2px(getContext(), 24);
            }
        }
        im_type.setLayoutParams(lp);
    }

    public String dateToStamp(String s) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //如果它本来就是long类型的,则不用写这一步
        long lt = new Long(s);
        Date date = new Date(lt*1000);
        res = simpleDateFormat.format(date);
        return res;

    }

}